﻿using LY.DataAccess.Repository;
using LY.Entity;
using LY.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Web;


namespace LY.Business.ServiceImpl
{
    public class DocumentService : IDocumentService
    {
        DocumentRepository _document;
        public DocumentService()
        {
            _document = new DocumentRepository();
        }
        public int AddImagesTodb(List<T_Document> dou)
        {
            var result = 0;
            foreach (var document in dou)
            {
                result = (int)_document.Insert(document);
            }
            return result;
        }
        //根据项目Id查询信息
        public List<T_Document> GetDocumentList(int? id)
        {
            return _document.GetDocumentList(id);
        }

        //删除
        public int DeleteImages(int? id)
        {
            DeleteFile(GetDocumentListbyId(id));
            return _document.DeleteImagesbyID(Convert.ToInt32(id));
        }

        private void DeleteFile(string path)
        {
            string mapPath = HttpContext.Current.Server.MapPath(path);
            if (System.IO.File.Exists(mapPath))
            {
                System.IO.File.Delete(mapPath);
            }
        }
        public string GetDocumentListbyId(int? id)
        {
            return _document.GetDocumentListbyId(id);
        }
    }
}
